package com.kogi.androidpatt.gettingInput.multipleItems;

import com.kogi.patterns.R;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

public class checkbox extends Activity 
{

	private CheckBox checkboxRed,checkboxGreen,checkboxBlue;
	private TextView colorBox;
	
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
        setContentView(R.layout.getting_input_checkbox);
        checkboxRed = (CheckBox) findViewById(R.id.checkBoxRed); 
        checkboxGreen = (CheckBox) findViewById(R.id.checkBoxGreen);
        checkboxBlue = (CheckBox) findViewById(R.id.checkBoxBlue);
        colorBox = (TextView)findViewById(R.id.colorBox);
        colorBox.setBackgroundColor(0x000000);
        checkboxRed.setOnClickListener(new CheckBox.OnClickListener() 
        {
			@Override
			public void onClick(View arg0) 
			{
				changeBoxColor();
			}
        });	
        checkboxGreen.setOnClickListener(new CheckBox.OnClickListener() 
        {
			@Override
			public void onClick(View arg0) 
			{
				changeBoxColor();
			}
        });	
        checkboxBlue.setOnClickListener(new CheckBox.OnClickListener() 
        {
			@Override
			public void onClick(View arg0) 
			{
				changeBoxColor();
			}
        });	
    }	
	
	protected void changeBoxColor()
	{
		int r,g,b;
		r = isChecked(checkboxRed);
		g = isChecked(checkboxGreen);
		b = isChecked(checkboxBlue);
		colorBox.setBackgroundColor(Color.rgb(r, g, b));
	}
	
	protected int isChecked(CheckBox ch)
	{
		if (ch.isChecked())
			return 255;
		else
			return 0;
	}
}